import torch
import torchvision
from torch import nn
from torch.utils.data import DataLoader


class MyMod(nn.Module):
    def __init__(self):
        super(MyMod, self).__init__()
        self.linear = nn.Linear(196608, 10)

    def forward(self, input):
        output = self.linear(input)
        return output


test_data = torchvision.datasets.CIFAR10(
    # 数据集下载路径
    "./dataset",
    download=True,
    # 测试数据集还是训练数据集
    train=False,
    # 图片是PIL格式，需要转换为tensor
    transform=torchvision.transforms.ToTensor()
)
mymod = MyMod()
test_loader = DataLoader(dataset=test_data, batch_size=64, shuffle=True, num_workers=0, drop_last=False)
for data in test_loader:
    imgs, targets = data
    print(imgs.shape)
    flatten_img = torch.flatten(imgs)
    print(flatten_img.shape)
    output = mymod(flatten_img)
    print(output.shape)
    break